package com.student.Activitys.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.student.Activitys.R;
import com.student.Activitys.activity.base.BaseActivity;
import com.student.Activitys.adapter.StageSeeAdapter;
import com.student.Activitys.adapter.base.BaseRecyleViewAdapter;
import com.student.Activitys.bean.pack.StageListJsonPack;
import com.odd.Activitys.http.manager.HomeManager;
import com.student.Activitys.utils.Constant;
import com.student.Activitys.utils.JumperUtils;

import org.simple.eventbus.Subscriber;
import org.simple.eventbus.ThreadMode;

import butterknife.Bind;

/**
 * 项目名称：智慧校园学生端
 * 类描述：阶段性评价 列表 （期中、期末）
 * 创建人：张飞祥
 * 创建时间：2017/10/17 9:06
 * 修改人：张飞祥
 * 修改时间：2017/10/17 9:06
 * 修改备注：
 */
public class StageSeeActivity extends BaseActivity {

    @Bind(R.id.iv_return)
    ImageView ivReturn;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.rv_stage_see)
    RecyclerView rvStageSee;

    //列表适配器
    private StageSeeAdapter adapter;
    //初始化网络请求
    public HomeManager mApiManager;
    //标题
    private String title;

    @Override
    protected void initUI() {
        setContentView(R.layout.act_stage_see);
        //网络请求 常驻方法
        mApiManager = mApiManager.getHomeApiManager(StageSeeActivity.this, StageSeeActivity.this.getTaskId());
    }

    @Override
    protected void initData() {

        //显示返回按钮
        ivReturn.setVisibility(View.VISIBLE);
        //初始化请求
        initHttp();
    }

    /**
     * 初始化网络请求
     */
    private void initHttp() {
        //显示 加载dialog
        initShowTimeDialog("正在加载本页面数据，请稍后...",StageSeeActivity.this);
        //开始网络请求
        mApiManager.stageSee(Constant.HTTP_HOME_STAGE_SEE_ACTION, xh);
    }

    @Override
    protected void getNotData() {

    }

    /**
     * 阶段性评价 数据 网络请求 加载是否成功
     */
    @Subscriber(tag = Constant.BUS_STAGE_SEE_ON_COMPLETED, mode = ThreadMode.MAIN)
    public void initTestingOnCompleted(String str) {
        //销毁handler
        time_handler.removeCallbacks(time_runnable);
        timeDailog.dismiss();
        dialog.dismiss();
    }
    /**
     * 阶段性评价 数据 网络请求 返回具体 数据实体
     */
    @Subscriber(tag = Constant.BUS_STAGE_SEE_STAGE, mode = ThreadMode.MAIN)
    public void homeDynamic(final StageListJsonPack pack) {
        if (pack.getDQJD().equals(Constant.QZPJ))
            title = "期中评价";
        else
            title = "期末评价";
        //设置动态标题
        tvTitle.setText(title);
        //状态评价列表
        adapter = new StageSeeAdapter(StageSeeActivity.this, pack.getDataList());
        //装填列表数据
        rvStageSee.setLayoutManager(new LinearLayoutManager(StageSeeActivity.this, LinearLayoutManager.VERTICAL, false));
        rvStageSee.setAdapter(adapter);
        /**
         * 条目点击事件
         */
        adapter.setOnItemClickListener(new BaseRecyleViewAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                //装填数据
                Bundle bundle = new Bundle();
                bundle.putParcelable(Constant.SCHEDULE_WEEK_BEAN,pack.getDataList().get(position));
                bundle.putString(Constant.PJSTYLE,pack.getDQJD());
                //跳转详情页面
                JumperUtils.JumpTo(StageSeeActivity.this,StageEvaluateActivity.class,bundle);
            }
        });
    }

    /**
     * 当前页面 刷新 消息通知
     */
    @Subscriber(tag = Constant.STAGE_SEE_REFRESH,mode = ThreadMode.MAIN)
    public void initRefresh(String str) {
        initHttp();
    }
}
